package hn.cch.job;

import org.quartz.CronTrigger;
import org.quartz.Job;
import org.quartz.JobDetail;
import org.quartz.JobExecutionContext;
import org.quartz.SimpleTrigger;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.text.ParseException;
import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;

/**
 * 测试任务
 */
public class ConfJob implements Job {

    private static Logger logger = LoggerFactory.getLogger(ConfJob.class);

    private static String nameJobGroup = "ConfJobGroup";
    private static String nameJobDetail = "ConfJobDetail";
    private static String nameCronTrigger = "ConfCronTrigger";
    private static String nameSimpleTrigger = "ConfSimpleTrigger";

    private static JobDetail testJobDetail  = new JobDetail(
        nameJobDetail, nameJobGroup,
        TestJob.class, false, false, true);

    private static void  initConfJob(){

        Date date = new Date();
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.add(Calendar.MINUTE, 1);
        Date time = calendar.getTime();

        TimeZone timeZone = TimeZone.getDefault();
        String timeCron = "59 * * * * ?";

        int repeatCount = 1;
        long repeatInterval = 1;


        //在程序启动时执行一次加载配置文件

        try {
            CronTrigger confCronTrigger = new CronTrigger(
                nameCronTrigger, nameJobGroup,
                nameJobDetail, nameJobGroup,
                date, time, timeCron, timeZone);


            SimpleTrigger confSimpleTrigger = new SimpleTrigger(
                nameSimpleTrigger, nameJobGroup,
                nameJobDetail, nameJobGroup,
                date, time, repeatCount, repeatInterval
            );


        } catch (ParseException e) {
            e.printStackTrace();
        }


        //第一次加载配置完成后定时加载配置


    }

    @Override
    public void execute(JobExecutionContext context) {

        logger.info("=#*-< conf begin >-*#=");




        logger.info("=#*-< conf end >-*#=");

    }



}
